GBML manual / Using the editor

Player movement

Pick how the player moves - a platformer, top-down, grid, ship, spin-and-thrust or auto-runner - tune it with numbers in pixels and seconds, add player actions (jump, dash, attack, shoot, interact, crouch, slide, block or your own) on buttons, see a drawing of the jump, and call it from the player's Step event.

What it is

Player movement is a ready-made way for the player to run, jump, walk or fly. You pick a style, tune it with numbers you can think in, add player actions (things the player can do on a button), and Gbabel writes a script that does it all. You can still read the script.

It lives in the Code tab, in a section called Player movement, under Behaviors. It moves things the same way the rest of Gbabel does, so it stops at the room's solid tiles, and at solid objects you name.

Make one

  1. Click + Movement in the section.
  2. Type a name, like player_move.
  3. Pick a style and a feel to start from. The styles fold open and shut. Platformer has Tight, Floaty and Heavy. Auto-runner has Gentle and Frantic. Top-down has Snappy, Smooth and Slippery. Grid has Quick and Relaxed. Ship has Fast and Careful. Spin and thrust has Classic and Heavy. A new movement works at once, and you can change every number afterward.
  4. Two windows open: the designer, with the picture, and Properties beside it, with all the numbers and the list of Player actions. A platformer or an auto-runner starts with a Jump action.

Click a name in the list to open it again. Right-click it to rename, duplicate, show the script or delete it.

Use it on the player

A movement is used by being called from an object's Step event:

player_move();

Pick the object in Used by under Use in an object. Gbabel then does two things for you:

It can run on the same object as a behavior: each one keeps its own numbers.

The numbers

Everything is in pixels and seconds, never raw physics. Under each number, small print says what it comes to in other units (frames, tiles). Worked out for you at the bottom of Properties lists what Gbabel worked out from your numbers.

Each group of numbers is a section you can fold. A slider shows its number while you drag it, and the picture follows at once. One drag is one undo step.

Platformer

SettingWhat it does
Run speedHow fast it runs at full speed, in pixels per second.
Time to full speed, Time to stopHow long it takes to speed up and to stop. A long stop slides like ice.
Steering in the airHow much you can steer in the air, in percent.
Fall gravityHow much harder it falls than it rises. 1 is the same; 2 is twice as hard.
Top falling speedThe fastest it can fall.
Wall slide, Wall jumpSlide slowly down a wall while you push toward it. Jump off a wall in the air, pushed away from it (a wall jump needs a Jump action).
LaddersClimb objects (and tiles with a flag you choose). Jump to let go.
One-way platformsObjects you can jump up through and then stand on. Hold down and press jump to drop through. It lands on a platform when its feet come down onto that platform's top, wherever the jump began: another platform beside it or just above it never makes it fall through. A jump that ends with the feet still below the top falls through.
Ride moving platformsA solid object that moves (on a path, or with a speed of its own) carries the player along, sideways and up and down, while the player stands on it. On for a new platformer. The platform must not have Never moves ticked, and it has to move by a path or by its own speed, not by changing its position in its own Step event.
Pushed by windLets other objects push the player: see Wind below.
Knocked back when hitGives the player a knock-back of its own: see Being hit below.

The jump (its height, time to the top, short hop, late jump, early jump and extra jumps) and the dash are actions now: see Player actions below. Gravity comes from the height and the time to the top of the Jump action. With no Jump action the player cannot jump and falls under standard gravity.

#### Wind

Tick Pushed by wind and the player gets two numbers, player_move_wind_x and player_move_wind_y, in pixels per second (the first part of the name is your movement's name). Any object can add to them. The movement adds them to the way the player moves this frame, stops at walls and floors like walking does, and then sets both back to 0, so a gust has to write them again every frame the player is inside it. Several gusts at once add up. A positive wind_x pushes right and a positive wind_y pushes down. An updraft has to be stronger than the player's falling speed to lift it. Give a wind zone object like this in its Step event, and give it a big collision box in its object settings:

var p = collision_rect(box_left, box_top, box_right, box_bottom, obj_player);
if (p != nothing) {
    p.player_move_wind_x += 60;
}

Writing the player's player_move_hsp instead does not work: the movement slows that number down again every frame, so a standing player never moves.

#### Being hit

Tick Knocked back when hit (in Being pushed) and the movement gets a call for the player's hit event, the same one a top-down player has:

player_move_knock(0, 120);

The first number is the direction the hit pushes the player (in degrees: 0 is right, 180 is left), the second how hard, in pixels per second. Call it from the player's own events, or from anywhere else inside with (obj_player) { ... }. Then the movement does the rest by itself:

Leave the tick box off and nothing about hits is added: the script, the variables and the saved design are exactly as they were.

Dying now stops the buttons too: when the Dying picture is chosen and your code sets player_move_dead to true, the player cannot walk, jump or use an action any more. (A design with no Dying picture never looks at player_move_dead.)

Top-down

Speed, Time to full speed, Time to stop, Directions (4 or 8). Dashes, hops and the rest are actions. An optional Run is an action you add in Player actions (+ Add an action > Run): pick its button, and while it is held and the player moves, it moves at its own Run speed and Time to run speed (both on the Run card) and plays the Running pictures (a facing with no running picture plays the walking one). With no run button chosen, nothing about running exists in the design or the script. The movement also gives you a call for the player's hit event:

player_move_knock(180, 120);

It pushes the player in that direction (in degrees: 0 is right, 90 is up, 180 is left) at that many pixels per second. The push fades out over Push lasts, and the player cannot steer for Cannot steer for seconds.

You can call it from anywhere, like any other script: the player's own events, an enemy's event, or another script. It pushes the object that runs it, so from anywhere other than the player's own events, reach the player first:

with (obj_player) {
    player_move_knock(180, 120);
}

Grid

Tile size, Time per step, Turn before walking (pressing a new direction only turns it, and holding walks) and Hold to keep walking. It always moves exactly one tile per step and never stops between tiles. Put the object in the middle of a tile.

Ship

Speed, Time to full speed and Stay on screen with its Edge space. The ship always has a Focus action in Player actions: pick its button, and Focus speed (how slowly it flies while that button is held) is on its card.

Spin and thrust

Turn speed, Drag (0 drifts forever), Top speed and Wrap around the screen. The ship always has a Thrust action in Player actions: pick its button, and Thrust (how hard it pushes forward while the button is held) is on its card. Draw the ship pointing to the right. The ship turns its picture, so it needs a console that can turn sprites.

Auto-runner

It runs by itself: Starting speed, Speeds up by (pixels per second, each second) and Top speed. Its jump is a Jump action, the same as the platformer's.

Player actions

An action is something the player can do when a button is pressed: jump, dash, attack, shoot, use something, crouch, slide, block, or anything of your own. They are a list in the Player actions section of Properties. Click + Add an action to add one, drag the grip on its left (or use the arrows) to move it, and click the ✕ to take it out. Undo brings it back.

The list is checked from the top. When two actions are on the same button, the first one whose rules hold takes the press. So put the action with the narrow rules (like "only in the air") above the one that is always allowed.

Each action is a card with small sections you can fold:

The kinds

KindWhat it does
JumpThe platformer's jump: Jump height, Time to the top (Gbabel works out gravity and jump speed), Short hop, Late jump, Early jump and Extra jumps in the air. There can be only one.
Hop (top-down)A quick hop the way the player faces. While it lasts the player passes over solid objects (not over the walls of the room).
DashA quick burst of speed the way the player faces: a dash or a roll. How long it lasts and Wait before again (the cooldown) are in its numbers, Ignore hits in During it makes the player safe while it lasts (player_move_invulnerable), and a top-down player has Animation: up and Animation: side beside the plain one for a picture per facing (roll_up, roll_side). In the air a platformer dashes once until it lands (a switch).
AttackPlays the attack animation, so the attack boxes you drew in the Animations window hit things (use "Its attack hits something", or the Attack Hits event). An optional Lunge pushes the player forward.
ShootMakes an object (like a bullet) in front of the player and sends it the way the player faces, at a speed you set. At most says how many can exist at once. A ship shoots up and a spinner shoots the way it points.
InteractFinds the nearest object of a kind that is in front of the player and close enough (Reach) and runs one of its User events (0 to 15). If there is none, the button goes on to the next action. An object can start a dialogue from its User event.
CrouchWhile the button is held the body is smaller (it shrinks from the top) and the player moves slower. Sets player_move_crouching.
SlideA slide along the floor with a smaller body.
BlockWhile the button is held, player_move_blocking is true, the player moves as you set in During it (usual, slower or not at all) and plays its own picture (block, block_up, block_side). Tick Guard against hits from the front (platformer and top-down) and player_move_knock treats a hit from the front as blocked: see Blocking below.
Custom actionYour own: the same button, rules, how long and wait, and a What it does list built with the cards of the Behaviors designer (play an animation or a sound, make an object, change a variable, run a script, If and otherwise). The cards run once, when it starts.

#### Blocking

With Guard against hits from the front ticked on a Block action (it shows Harm still taken, 0 to 100 percent, and Push-back), call player_move_knock from your hit code as before, then use what it tells you:

var ex = x;
var ey = y;
with (obj_player) {
    player_move_knock(dir_to(ex, ey, x, y), 120);
    hp -= 2 * player_move_harm;
    if (player_move_blocked) {
        sound_play(snd_clang);
    }
}

While the button is held and the hit comes from the front (the way the player faces, within 60 degrees either side), the player is not knocked back or stunned, it is only pushed back a little, player_move_blocked is true (read it right after the call, or until the end of the next frame the movement runs), and player_move_harm is the share of the damage to take: 0 when Harm still taken is 0, 0.5 for 50. A hit from behind or the side is the full hit and player_move_harm is 1. The harm itself is yours: the movement only tells you how much of it counts. Without the tick nothing of this exists.

An action's numbers are variables of the object too, so the Inspector can change them while you play and Keep these brings the ones you changed there into the window. A number you move in the window goes into the playing game by itself. In the Play tab, the window beside the game has a Player movement tab with the numbers (and a list to pick the movement when your game has more than one), so you can tune the jump while you watch it. Sounds, animations, buttons, on/off options, actions and the style are not in that tab: they change the script and take effect after Build & Play (while a game plays, the designer tells you so when you change one). The tab's Open in the designer button opens the full designer. The first action of a kind keeps the plain names (player_move_height, player_move_dashspd); the others use their own name (player_move_dash_2_speed).

Older designs

A movement made before actions existed opens as the same behavior: its jump becomes a Jump action and its dash a Dash action, with the same numbers, buttons, sound and animation.

The picture

For a platformer or runner, the picture is the jump arc drawn over a grid with one square for each tile. It shows how high a full jump goes, how far it reaches at your run speed (the gap it clears), and, in orange, a quick tap. It redraws as you move a slider. The other styles show a speed curve (or the tiles of one step).

Buttons, animations and sounds

- Landing (platformer) plays once when the player touches the ground after being in the air. Make the animation play once and go on to idle: the landing is over when it has. A jump pressed on the landing frame shows the jump, not the landing. - Hit and Dying (platformer): the movement does not know when the player is hit or dies, so your own code tells it. Hit plays while player_move_hurt_left (a number of frames) is above 0, so a hit event can set it to, say, 20. Dying plays while player_move_dead is true and wins over every other picture. Hit also plays by itself when Knocked back when hit is on (see Being hit). Dying also stops the buttons. - Top-down: a picture for each way it faces. Standing, walking, running (when a run button is chosen) and being hit each have three slots: down, up and sideways. Draw the sideways pictures facing right: facing left plays the same picture flipped, and an up or down picture is never flipped. A facing you leave empty plays the down one. Hit plays while the player is knocked back (the knock-back call) and follows the way it faces. Dying has one picture and plays while player_move_dead is true. The way it faces is its last move: up when that was straight up, sideways when it had a step sideways, and down otherwise. With nothing chosen for up and sideways, the player plays and flips exactly as before. - Each action of a top-down player also has Animation: up and Animation: side beside its plain animation (the plain one is facing down), so a roll or an attack can be drawn per facing. Fill from the names looks for names ending in _down, _up and _side (roll_up, attack_sword_side).

Tune while playing

The numbers are variables of the object, so you can change them while the game plays. Press Quick Play (the game plays at once, nothing is built) or Build & Play, then move a slider in the window (for example Jump height): the playing game gets the new number at once. You can also open the player in the Inspector and change player_move_height or player_move_run there; then press Keep these and the window takes those numbers (one undo step). Keep these never undoes a number you changed in the window. If no game is playing, it says so. When the game makes the player again (a room that starts over, coming back after a game over), the new player begins with the numbers the game was built with; the window notices within a second and puts the numbers you moved back in.

Worked examples

A platformer. Pick Platformer > Tight. Use it on obj_player. Open the Jump card in Player actions and make the jump 56 pixels high by dragging Jump height: the picture shows the new arc and says how many tiles it clears. Tick Wall jump, add a Dash action, play, and press Keep these after you tune it in the Inspector.

A hero with a sword and a bow. Add an Attack on B that only works on the ground, and a Shoot on B that only works in the air: the first whose rules hold takes the button. Add a rule to the attack, "the player has the sword", so it only works after the player picks the sword up.

A top-down game. Pick Top-down > Smooth. Use it on obj_player. Set Directions to 4 for a classic adventure. In the player's collision event with an enemy, call player_move_knock(0, 120); to push it back.

A grid puzzle. Pick Grid > Relaxed. Set Tile size to the size of your room's tiles and put the player in the middle of a tile. Mark the crates Solid in their object settings (and keep Stop at solid objects ticked) so it cannot walk through them.

A shoot-em-up. Pick Ship > Fast. Its Focus action is already in Player actions: set its button to B. Stay on screen keeps it in view.

An asteroid field. Pick Spin and thrust > Classic. Draw the ship pointing right, give it a thrust animation, and the button of its Thrust action (A) pushes it forward.

An endless runner. Pick Auto-runner > Gentle. The player runs by itself and the picture shows how far each jump clears at the start and at the top speed. Put gaps in the room that are narrower than that.

The script belongs to the designer

The script is read-only in the code editor, because it is written again every time you change the design. At the top of its window you see Made by the player movement designer and two buttons: Open in designer, and Make it my own script. The second one copies the script into a new, ordinary script you can edit. The copy is no longer connected to the designer, and it keeps using the same numbers.

Rename, delete and saving

Good to know

See also: The Code tabScriptsBehaviorsThe Inspector - looking inside a playing gamemove_slidemove_slide_solidtile_freepos_freepos_meetingapproachbtn_dxbtn_heldbtn_pressedbtn_releasedanimation_playsound_playmove_wrapmove_toangleflip_xdir_xtile_flagscamera_xinstance_createinstance_countinstance_nearestevent_call